#include<stdio.h>
#include<stdbool.h>
struct TreeNode
{
	int val;
	struct TreeNode* left;
	struct TreeNode* right;
};


int maxDepth(struct TreeNode* root)
{
	if (root == NULL)
	{
		return 0;
	}
	int leftdeep = maxDepth(root->left);
	int rightdeep = maxDepth(root->right);
	return leftdeep > rightdeep ? leftdeep + 1 : rightdeep + 1;
}
bool isBalanced(struct TreeNode* root)
{
	if (root == NULL)
	{
		return true;
	}
	int leftdeep = maxDepth(root->left);
	int rightdeep = maxDepth(root->right);
	return abs(leftdeep - rightdeep) < 2 && isBalanced(root->left) && isBalanced(root->right);
}